<script setup lang="ts" name="NoticeDetail">
import { getNoticeApi } from "@/api/system/notice";

const { sys_notice_type, sys_notice_status } = useDict("sys_notice_type", "sys_notice_status");

const emit = defineEmits(['closeDialog']);

const props = defineProps({
  id: {
    default: null,
  },
  title: {
    type: String,
    default: false,
  }
});
const open = ref(false);

const form = ref<NoticeRecord>({});

/** 获取通知公告详情 */
function getData() {
  if (isEmpty(props.id)) {
    open.value = true;
  } else {
    getNoticeApi(props.id).then(response => {
      form.value = response.data;
      open.value = true;
    }).catch(() => {
      closeDialog(false);
    })
  }
}

/** 关闭弹窗 */
function closeDialog(refresh: boolean) {
  open.value = false;
  emit("closeDialog", refresh);
}

watch(open, (val) => {
  if (!val) {
    closeDialog(false);
  }
});

getData();
</script>

<template>
  <!-- 通知公告详情对话框 -->
  <el-dialog :title="title" v-model="open" width="700px" append-to-body>
    <div class="detail-form">
      <el-form ref="noticeForm" :model="form" label-width="80px">
        <el-form-item label="公告标题" prop="noticeTitle" class="item-describe">
          {{ form.noticeTitle }}
        </el-form-item>
        <el-form-item label="公告类型" prop="noticeType">
          <dict-tag :options="sys_notice_type" :value="form.noticeType" />
        </el-form-item>
        <el-form-item label="状态" prop="status">
          <dict-tag :options="sys_notice_status" :value="form.status" />
        </el-form-item>
        <el-form-item label="创建者" prop="createBy">
          {{ form.createBy }}
        </el-form-item>
        <el-form-item label="创建时间" prop="createTime">
          {{ form.createTime }}
        </el-form-item>
        <el-form-item label="内容" prop="noticeContent" class="item-describe item-content">
          <div v-html="form.noticeContent">
          </div>
        </el-form-item>
      </el-form>
    </div>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="closeDialog(false)">取 消</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<style lang="scss" scoped>
:deep(img){
  width: 100%;
}
</style>